<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="${staticServer}/inc/style/main.css"/>
    <link rel="stylesheet" href="${staticServer}/inc/style/page.css"/>
    <link rel="stylesheet" href="${staticServer}/css/work_today.css"/>
    <link rel="stylesheet" href="${staticServer}/css/lanrenzhijia.css"/>
    <script src="${staticServer}/inc/js/jquery.js"></script>
    <script src="${staticServer}/inc/js/pageset.js"></script>
    <script>
        $(function () {
            $("#nickname").val("${nickName}");

        });

        var selectMsg = function () {
            var nickName = $("#nickname").val();
            window.location.href = encodeURI("${contextPath}/index/sales_executive.htm?nickName=" + nickName);
        }

        function starquery(type) {
            if (type == 0) {
                var name = $("#nickname").val();
                var param = "";
                if (name != "") param += "&n=" + name;

                location.href = "?" + param;
            }
            else {
                location.href = "?";
            }
        }
        function addPerformanceInfo(flag, name, id, childenUsernames, pay, performanceId) {
            if (flag == 1) {
                $("#flag").val("1");
                $("#performanceId").val(performanceId);
                $("#levle").val(pay);
                $("#username").hide();
                $("#updateper").empty();
                $("#updateper").append("<option value='" + id + "'>" + name + "</option>");
                $("#updateper").show();
                var strs = new Array(); //定义一数组
                strs = childenUsernames.split(","); //字符分割
                for (i = 0; i < strs.length; i++) {
                    $("#childen  option[value='" + strs[i] + "']").attr("selected", true);
                }

            } else {
                $("#flag").val("0");
                $("#username").show();
                $("#updateper").hide();
            }
            $('.theme-popover-mask').fadeIn(100);
            $('.theme-popover').slideDown(200);
            $('.theme-poptit .close').click(function () {
                $('.theme-popover-mask').fadeOut(100);
                $('.theme-popover').slideUp(200);
            })
        }
        function myAjax(id, user) {
            var childenUserNames = "";
            var childenNames = "";
            var levelText = $("#levle option:selected").text();
            var levelValue = $("#levle option:selected").val();
            var performanceId = $("#performanceId").val();
            $("#childen option:selected").each(function () {
                childenUserNames += $(this).attr("value") + ":";
                childenNames += $(this).text() + ":";
            });
            $.ajax({
                type: 'POST',
                url: 'addSalesExecutive.htm',
                data: {
                    "user": user,
                    "childenUserNames": childenUserNames,
                    "childenNames": childenNames,
                    "id": id,
                    "levelText": levelText,
                    "levelValue": levelValue,
                    "performanceId": performanceId
                },
                dataType: "text",
                success: function (data) {
                    if (data == "1") {
                        alert("操作成功");
                        window.location.href = encodeURI("${contextPath}/index/sales_executive.htm");
                    } else if (data == "0") {
                        alert("该用户已经存在!");
                    }
                },
                error: function () {
                    alert("服务器发生错误!!");
                }
            });
        }
        function save() {
            var flag = $("#flag").val();
            if (flag == 0) {
                var user = $("#username option:selected").val();
                myAjax(0, user);
            } else {
                var id = $("#updateper option:selected").val();
                myAjax(id, "");
            }

        }
        function selectSalesExe() {
            //获取选中的销售主管
            var user = $("#username option:selected").val();
            var strs = new Array();
            strs = user.split(",");
            //给底下的select赋值
            $("#childen").val(strs[0]);

        }

    </script>
</head>

<body>
<div id="home_link">
    <ul>
        <li></li>
        <li>&gt;</li>
        <li>帐号管理</li>
        <li>&gt;</li>
        <li class="current"></li>
    </ul>
</div>
<div id="container">
    <div id="title"></div>
    <table class="form_table">
        <tr>
            <td><label><b>查询条件：</b></label>
                <label for="nickname">姓名：</label>
                <input type="text" name="nickname" id="nickname" size="15" value=""/>
                <input type="button" value=" 查 询 " onclick="selectMsg()"/>
                <input type="button" value=" 添 加 " onclick="addPerformanceInfo()"/>
            </td>
        </tr>
    </table>
    <table>
        <tr class="fields">
            <th>主管帐号</th>
            <th>主管姓名</th>
            <th>人员</th>
            <th width="20%">操作</th>
        </tr>

    <#if list??>
        <#list list as list>
            <tr class="even_row">
                <td align="center" class="stress">${list.username}</td>
                <td align="center" rel="nohover">
                    <a title="${list.info}">
                        <span>${list.name}</span></a>
                </td>
                <td align="center" class="stress">
                    <select>
                        <#if list.myChilden??>
                            <#list list.myChilden as myChilden>
                                <option> ${myChilden}</option>
                            </#list>
                        </#if>
                    </select>
                </td>
                <td align="center">
                    <input type="button" class="btn btn-primary" value="修改"
                           onclick="addPerformanceInfo(1,'${list.name}','${list.id}','${list.childenUsernames}','${list.pay}','${list.performanceId}')"/>
                </td>
            </tr>
        </#list>
    </#if>
    </table>
</div>
<div id="pager" style="width: 849px;">
    <ul id="pagination">
    <#if page??>
        <#if page.pagetotal?? && page.pagetotal!="0">
            <#assign pagetotal = page.pagetotal>
        <#else>
            <#assign pagetotal = 1>
        </#if>
        <#if page.currpage??>
            <#assign currpage = page.currpage>
        <#else>
            <#assign currpage = 1>
        </#if>
        <#if currpage==1 >
            <li class="previous-off">上一页</li>
        <#else>
            <li class="previous"><a
                    href="${contextPath}/index/sales_executive.htm?currPage=${currpage-1}&nickName=${nickName}">上一页</a>
            </li>
        </#if>

        <#if pagetotal<=11>
            <#list 1..pagetotal as index_up>
                <#if currpage==index_up >
                    <li class="current">${index_up}</li>
                <#else>
                    <li>
                        <a href="${contextPath}/index/sales_executive.htm?currPage=${index_up}&nickName=${nickName}">${index_up}</a>
                    </li>
                </#if>
            </#list>
        <#else>
            <#if currpage<=8 >
                <#list 1..9 as index_up>
                    <#if currpage==index_up >
                        <li class="current">${index_up}</li>
                    <#else>
                        <li>
                            <a href="${contextPath}/index/sales_executive.htm?currPage=${index_up}&nickName=${nickName}">${index_up}</a>
                        </li>
                    </#if>
                </#list>
                <li>...</li>
                <li>
                    <a href="${contextPath}/index/sales_executive.htm?currPage=${pagetotal}&nickName=${nickName}">${pagetotal}</a>
                </li>

            <#elseif (currpage>= 9 && currpage<pagetotal-7)  >
                <li><a href="${contextPath}/index/sales_executive.htm?currPage=1&nickName=${nickName}">1</a></li>
                <li>...</li>
                <#list currpage-3..currpage+3 as index_up>
                    <#if currpage==index_up >
                        <li class="current">${index_up}</li>
                    <#else>
                        <li>
                            <a href="${contextPath}/index/sales_executive.htm?currPage=${index_up}&nickName=${nickName}">${index_up}</a>
                        </li>
                    </#if>
                </#list>
                <li>...</li>
                <li>
                    <a href="${contextPath}/index/sales_executive.htm?currPage=${pagetotal}&nickName=${nickName}">${pagetotal}</a>
                </li>
            <#else>
                <li><a href="${contextPath}/index/sales_executive.htm?currPage=1&nickName=${nickName}">1</a></li>
                <li>...</li>
                <#list pagetotal-8..pagetotal as index_up>
                    <#if currpage==index_up >
                        <li class="current">${index_up}</li>
                    <#else>
                        <li>
                            <a href="${contextPath}/index/sales_executive.htm?currPage=${index_up}&nickName=${nickName}">${index_up}</a>
                        </li>
                    </#if>
                </#list>
            </#if>

        </#if>
        <#if currpage==pagetotal >
            <li class="previous-off">下一页</li>
        <#else>
            <li class="previous"><a
                    href="${contextPath}/index/sales_executive.htm?currPage=${currpage+1}&nickName=${nickName}">下一页</a>
            </li>
        </#if>
        <li class="pageinfo">共${page.total}条记录</li>
    </#if>
    </ul>
</div>
<div class="emptyline"></div>
<div class="theme-popover">
    <div class="theme-poptit">
        <a href="javascript:;" title="关闭" class="close">×</a>
        <h3>添加</h3>
    </div>
    <div class="theme-popbod dform">
        <form class="theme-signin">
            <ol>
                <li><strong>销售主管：</strong>
                    <select id="username" onchange="selectSalesExe()">
                    <#if uList??>
                        <#list uList as list>
                            <option value="${list.username},${list.nickname}">${list.nickname}
                                （${list.regions}-${list.departments}-${list.job}）
                            </option>
                        </#list>
                    </#if>
                    </select>
                    <select id="updateper">
                    </select>
                    <select id="levle">
                        <option value="2150">区域主管M2</option>
                        <option value="2850">大区域主管M3</option>
                        <option value="3550">区域经理M4</option>
                        <option value="4250">大区域经理M5</option>
                        <option value="4950">销售副总监M6</option>
                        <option value="5650">销售总监M7</option>
                        <option value="6350">销售副总裁M8</option>
                        <option value="7050">总经理M9</option>
                        <option>总裁M10</option>
                    </select>
                <li style="">
                    <select id="childen" multiple="multiple" size="10">
                    <#if uList??>
                        <#list uList as list>
                            <option value="${list.username}">${list.nickname}
                                （${list.regions}-${list.departments}-${list.job}）
                            </option>
                        </#list>
                    </#if>
                    </select>
                <li>
                    <input type="hidden" id="flag" value="0">
                    <input type="hidden" id="performanceId">
                    <input class="btn btn-primary" type="button" onclick="save()" value=" 保 存 "/></li>
            </ol>
        </form>
    </div>
</div>
<div class="theme-popover-mask"></div>
</body>
</html>